package com.ffapp.f9164.td.view;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.ffapp.f9164.td.R;
import com.ffapp.f9164.td.login.HelpActivity;
import com.ffapp.f9164.td.login.LoginView;
import com.flyco.dialog.widget.NormalDialog;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import my.ActivityTool;

public class PopHandle extends NormalDialog {

    @BindView(R.id.pop_title_up)
    ImageView popTitleUp;
    @BindView(R.id.pop_title_mes)
    ImageView popTitleMes;
    @BindView(R.id.ll_app_update)
    LinearLayout llAppUpdate;
    @BindView(R.id.ll_file)
    LinearLayout llFile;
    @BindView(R.id.btn_app_upgrade)
    Button btnAppUpgrade;
    @BindView(R.id.btn_upload)
    Button btnUpload;
    @BindView(R.id.btn_file_upgrade)
    Button btnFileUpgrade;
    @BindView(R.id.btn_again)
    Button btnAgain;
    @BindView(R.id.btn_close)
    Button btnClose;
    @BindView(R.id.btn_help)
    Button btnHelp;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.tv_content)
    TextView tvContent;
    private Activity mActivity;
    private String type;
    private String title;
    private String content;
    private LoginView loginView;

    public PopHandle(Activity context, String type) {
        super(context);
        mActivity = context;
        this.type = type;
    }

    public PopHandle(Activity context, String type,String title,String content) {
        super(context);
        mActivity = context;
        this.type = type;
        this.title = title;
        this.content = content;
    }

    public PopHandle(Activity context, String type, LoginView loginView) {
        super(context);
        mActivity = context;
        this.type = type;
        this.loginView = loginView;
    }

    @Override
    public View onCreateView() {
        View inflate = LayoutInflater.from(mContext).inflate(R.layout.pop_handle, null);
        ButterKnife.bind(this, inflate);
        return inflate;
    }


    //    @Override
    public View onCreatePopupView() {
        View inflate = LayoutInflater.from(mContext).inflate(R.layout.pop_handle, null);
        ButterKnife.bind(this, inflate);
        return inflate;
    }

    @Override
    public void setUiBeforShow() {
        switch (type) {
            case "app_update":
                popTitleUp.setVisibility(View.VISIBLE);
                llAppUpdate.setVisibility(View.VISIBLE);
                tvTitle.setText("App升级提醒");
                tvContent.setText("确认升级吗？");
                btnAppUpgrade.setVisibility(View.VISIBLE);
                btnClose.setVisibility(View.VISIBLE);
                break;
            case "connect_fail":
                popTitleMes.setVisibility(View.VISIBLE);
                llAppUpdate.setVisibility(View.VISIBLE);
                tvTitle.setText("温馨提示");
                tvContent.setText("未发现设备，请确认设备已经开机并接近手机");
                btnHelp.setVisibility(View.VISIBLE);
                btnAgain.setVisibility(View.VISIBLE);
                break;
            case "tips_fail":
                popTitleMes.setVisibility(View.VISIBLE);
                llAppUpdate.setVisibility(View.VISIBLE);
                tvTitle.setText(""+title);
                tvContent.setText(""+content);
                btnHelp.setVisibility(View.GONE);
                btnAgain.setVisibility(View.GONE);
                btnClose.setVisibility(View.VISIBLE);
                break;
        }
    }



    @OnClick(R.id.btn_close)
    void close() {
        dismiss();
    }


    @OnClick(R.id.btn_help)
    void toHelp() {
        dismiss();
        ActivityTool.skipActivity(mContext,HelpActivity.class);
    }
    @OnClick(R.id.btn_again)
    void btnAgain() {
        dismiss();
        loginView.tryAgain();
    }


}